<template>
  <div id="addstock">
    <el-dialog   :title="edit==0?'添加库存':'修改库存'" :visible.sync="active" width="40%" top="3vh" :close-on-click-modal='true'>
      <div v-loading="loading" style="width:100%;margin: 0 auto;padding-bottom:20px;">
<!--        <div style="margin-top:10px;" class="tabbox">-->
<!--          <p style=""><a style="color:red;">* </a>物料编码</p>-->
<!--          <el-input  style='width:75%;' placeholder="请输入" v-model="datas.sku" clearable></el-input>-->
<!--        </div>-->
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>名称</p>
          <el-input  style='width:75%;' placeholder="请输入" v-model="datas.name" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>类型</p>
          <el-select  style="width:75%;border:none;" class="pboxc1" v-model="datas.typeId"  placeholder="请选择">
            <el-option v-for='item in $store.state.user.leidata' :key='item.id' :label="item.name" :value="item.id"></el-option>
          </el-select>
        </div>
        <div  style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>尺寸</p>
          <el-input style='width:75%;' placeholder="请输入" v-model="datas.size" clearable></el-input>
        </div>
        <div  style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>型号</p>
          <el-input style='width:75%;' placeholder="请输入" v-model="datas.model" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;">* </a>数量</p>
          <el-input  style='width:75%;' placeholder="请输入" v-model="datas.amount" clearable></el-input>
        </div>
        <div  style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;"> </a>摆放位置</p>
          <el-input style='width:75%;' placeholder="请输入" v-model="datas.location" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;"> </a>供应商</p>
          <el-input  style='width:75%;' placeholder="请输入" v-model="datas.provider" clearable></el-input>
        </div>
        <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;"> </a>单价</p>
          <el-input  style='width:75%;' placeholder="请输入" v-model="datas.price" clearable></el-input>
        </div>
        <div style="margin-top:10px;height:100px" class="tabbox">
          <p style=""><a style="color:red;"> </a>物品备注</p>
          <el-input style='width:75%;' clearable type="textarea" :rows="4" placeholder="请输入内容" v-model="datas.remarks"></el-input>
        </div>
        <!-- <div style="margin-top:10px;" class="tabbox">
          <p style=""><a style="color:red;"> </a>更新时间</p>
          <el-input  style='width:75%;' placeholder="请输入" v-model="datas.upTime" clearable></el-input>
        </div> -->
      </div>
      <div style="width:100%;height:40px;margin-top:20px;">
        <div style="width:170px;margin: 0 auto;">
          <el-button type="danger" @click="$parent.hidn()" >取 消</el-button>
          <el-button type="primary" @click="gitact" style='float:right;'>确 定</el-button>
        </div>
      </div>
    </el-dialog>

  </div>
</template>
<script>
  import { register_edit } from '@/api_bast/user'
  import {addStock} from '@/api_bast/stock.js'
  export default {
    name: 'adduser',
    computed:{
        indexof(){//查询返回(下标+1)
          return (id,data)=>{
              for(let i in data){
                  if(id==data[i].id){
                    return Number(i)+1;
                  }
              }
          }
        }
    },
    data() {
      return {
        loading:false,
        active:false
      }
    },
    props:{
      datas:Object,
      edit:Number
    },
    methods: {
      qf(){ //取反，active等于自己的相反数
        return this.active = !this.active
      },
      gitact(){//提交数据
        // console.log(this.datas);
        // if(this.isNull(this.datas.sku)){this.$message({message: '请输入 物料编码',type: 'error'});return false}
        // if(!this.isChn(this.datas.sku)){this.$message({message: '物料编码格式不对',type: 'error'});return false}
        if(this.isNull(this.datas.name)){this.$message({message: '请输入 名称',type: 'error'});return false}
        if(!this.datas.typeId){this.$message({message: '请选择 物品类型',type: 'error'});return false}
        if(this.isNull(this.datas.size)){this.$message({message: '请输入 尺寸',type: 'error'});return false}
        if(this.isNull(this.datas.model)){this.$message({message: '请输入 型号',type: 'error'});return false}
        if(this.isNull(this.datas.amount)){this.$message({message: '请输入 数量',type: 'error'});return false}
		    if(this.isNull(this.datas.location)){this.$message({message: '摆放位置 不能为空',type: 'error'});return false}
		    if(this.isNull(this.datas.provider)){this.$message({message: '供应商 不能为空',type: 'error'});return false}
        if(this.isNull(this.datas.price)){this.$message({message: '请输入 单价',type: 'error'});return false}
        this.loading=true;
        addStock(this.edit,this.datas).then(res=>{
          if(res.code == 200){
            this.$parent.get_data() //重新获取数据
            this.$parent.hidn(); //关闭信息框
            this.$notify.success({title: '成功',message: res.message});
          }
          this.loading=false;
        }).catch(()=>{});
      }
    },
    mounted() {
    }
  }
</script>

<style scoped>
  .tabbox{
    width:100%;
    height:40px;
    line-height: 30px;
    margin-top:23px;
  }
  .tabbox p{
    font-size:14px;
    color:#000000;
    width:17%;
    text-align:right;
    margin-right:5%;
    float:left;
    overflow: hidden;
    text-overflow:ellipsis;
    white-space: nowrap;
    font-family:Source Han Sans CN;
  }
</style>
